package 新增道路查询后的最短距离I;

public class Solution {
    public int[] shortestDistanceAfterQueries(int n, int[][] queries) {
        int[] arr = new int[n];
        for (int i = 0; i < n - 1; i++) {
            arr[i] = i + 1;
        }
        int[] out = new int[queries.length];
        int index = 0;
        for (int i = 0; i < queries.length; i++) {
            arr[queries[i][0]] = queries[i][1];
            int temp = 0;
            int count = 0;
            while (temp != n - 1) {
                count++;
                temp = arr[temp];
            }
            out[index++] = count;
        }
        return out;
    }
}
